package com.it.gw.modules.station.adapter

import StationTypeDtos
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.it.data.manager.DataManager
import com.it.gw.databinding.ItemGwRunningDataBinding


class GWRunningDataAdapter(
    var context: Context,
    var listener: (StationTypeDtos) -> Unit,
    var datas: List<StationTypeDtos>
) : RecyclerView.Adapter<GWRunningDataAdapter.ViewHolder>() {
    companion object {
        const val TAG = "GWRunningDataAdapter"
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ViewHolder {
        val binding =
            ItemGwRunningDataBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }


    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = datas[position]
        Log.d(TAG, "onBindViewHolder: $data")
        holder.binding.t1.setText(data.sttp)
        holder.binding.t2.setText(DataManager.formatDouble(data.existingTotal.toDouble()))
        holder.binding.t3.setText(DataManager.formatDouble(data.normalSite.toDouble()))
        holder.binding.t4.setText(DataManager.formatDouble(data.arrivalReport.toDouble()))

        holder.binding.root.setOnClickListener {
            listener.invoke(data)
        }

    }


    override fun getItemCount() = datas.size

    class ViewHolder(val binding: ItemGwRunningDataBinding) : RecyclerView.ViewHolder(binding.root)
}